package com.lexian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lexian.entity.Customer;
import com.lexian.entity.Recaddr;
import com.lexian.mapper.RecaddrMapper;
import com.lexian.service.RecaddrService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lexian.utils.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * <p>
 * 收货地址 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-01-14
 */
@Service
public class RecaddrServiceImpl extends ServiceImpl<RecaddrMapper, Recaddr> implements RecaddrService {
    @Autowired
    private RecaddrService recaddrService;
    /**
     * 修改地址
     * @param recaddr 地址
     * @return
     */
    @Override
    public void modifyRecaddr(Recaddr recaddr){
        QueryWrapper queryWrapper=new QueryWrapper();
        recaddrService.update(recaddr,queryWrapper);
    }

    /**
     * 添加地址
     * @param recaddr
     * @return
     */
    @Override
    public void addRecaddr(Recaddr recaddr){
        recaddrService.save(recaddr);
    }

    /**
     * 查询用户地址
     * @param cusId
     * @return
     */
    @Override
    public List<Recaddr> getAllRecaddr(Long cusId){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("cus_id",cusId);
        List<Recaddr> list = recaddrService.list(queryWrapper);
        return list;
    }

    /**
     * 删除地址
     * @param recaddrId
     * @return
     */
    @Override
    public void deleteRecaddrByrecaddrId(Long recaddrId){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("recaddr_id",recaddrId);
        recaddrService.remove(queryWrapper);
    }

    /**
     * 使用指定地址
     * @param recaddrId
     * @return
     */
    @Override
    public Recaddr getRecaddrByrecaddrId(Long recaddrId){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("recaddr_id",recaddrId);
        return recaddrService.getOne(queryWrapper);
    }
}
